草庐IT

C++11 auto 和 size_type

全部标签

c++11 将 std::tuple 解压到虚拟成员函数中

完整故事:我正在尝试构建一个看起来有点像这样的框架:#include#includeusingnamespacestd;//thisclassallowsusertocall"run"withoutanyargsclasssimulation_base{public:intrun(){execute_simulation_wrapped();};protected:virtualintexecute_simulation_wrapped();{return0;};}//thisclassfunnelssomestoredinputsintoasoon-to-be-overriddenm

c++ - 获取错误 : 'mutex' in namespace 'std' does not name a type in MinGW mysys prompt

我已经从官方网站下载了MinGW并将其安装在我的Windows8.1机器上。运行g++--version给我g++.exe(GCC)4.8.1。我正在尝试在MinGW编译器中编译现有的代码库,但它因以下错误而失败:error:'mutex'innamespace'std'doesnotnameatypeprivate:std::mutexm_Mutex;^error:'condition_variable'innamespace's还有更多与锁定和线程相关的错误。!我能够在Cygwin-64中编译相同的代码库,没有任何问题。我需要在MinGW中成功构建和编译,以便创建一些与MSVS兼容

c++ - 为什么我不能在 C++11 中使用 constexpr 指针作为模板参数?

请考虑以下代码:templatestructH{};structAA{inti;};intmain(){typedefintAA::*PI;constexprPIpi=&AA::i;Hh1;//OK//Hh2;//compileerror}我有成员指针pi指向AA::i。pi是一个constexpr变量。为什么我不能将它用作模板参数,即使直接使用&AA::i也可以? 最佳答案 因为这些是规则,至少在C++11中是这样;14.3.2/1仅允许“指向成员的指针,如5.3.1中所述”,它描述了&AA::i语法。这在latestdraft中

c++ - std::vector::resize(size_type) 需要 CopyInsertable?

这个问题是在我回答thisanotherquestion的时候提出的.N333723.3.6.3“vector容量”说(在770页):voidresize(size_typesz);Effects:Ifsz,equivalenttoerase(begin()+sz,end());.Ifsize(),appendssz-size()value-initializedelementstothesequence.Requires:TshallbeCopyInsertableinto*this.然而,clang++saysit'sokaythoughTisnotcopyable.我认为resiz

c++ - auto stdMaxInt = std::max<int> 的类型推导失败;

使用GCC4.8.4和g++--std=c++11main.cpp输出以下errorerror:unabletodeduce‘auto’from‘max’autostdMaxInt=std::max;对于这段代码#includetemplateconstT&myMax(constT&a,constT&b){return(a;myMaxInt(1,2);autostdMaxInt=std::max;stdMaxInt(1,2);}为什么它适用于myMax但不适用于std::max?我们可以让它与std::max一起工作吗? 最佳答案

c++ - 将函数转发到 c++11 中的 lambda 表达式

对于C++11中的Packaged_Task实现我想实现我在下面的C++14代码中表达的内容。换句话说,我想转发到lambda表达式中。templatePackaged_Task(F&&f){Promisep;_future=p.get_future();autof_holder=[f=std::forward(f)]()mutable{returnstd::move(f);};///...我知道转移到lambda的解决方法(但不幸的是,这个解决方法需要一个默认的可构造对象,在我的例子中,对象通常是没有默认构造函数的lambda表达式) 最佳答案

c++ - constexpr if with initializer 由标准保证吗? 'constexpr(constexpr auto x = f(); x) { }'

我找不到任何关于新C++17if初始化语法的信息和“constexprif”在:http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0128r1.html不过,Clang-HEAD支持该语法...constexprautof(){returntrue;}intmain(){ifconstexpr(constexprautox=f();x){}}在线代码在这里->http://melpon.org/wandbox/permlink/dj3a9ChvjhlNc8nr是constexprif带有标准保证的初始值设定项,如constexpr

c++ - type 不提供调用操作符

我有这个功能,order,返回vectorvectororder(vectornodes,vector>dependencies){Graphgraph=buildGraph(nodes,dependencies);vectororder=buildOrder(graph.getNodes());returnorder;}我这样调用它:vectororder2=order(nodes,deps);然而,编译器给出了这个错误:error:type'std::__1::vector>'doesnotprovideacalloperatorvectororder2=order(nodes,d

c++ - 标准 C++11 是否保证传递给函数的临时对象会在函数结束后被销毁?

众所周知,标准C++11保证传递给函数的临时对象将在函数调用之前创建:DoesstandardC++11guaranteethattemporaryobjectpassedtoafunctionwillhavebeencreatedbeforefunctioncall?但是,标准C++11是否保证传递给函数的临时对象会在函数结束后(而不是之前)被销毁?C++编程语言标准工作草案2016-07-12:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf§12.2Temporaryobjects§12.2/5Th

c++ - 为什么 C++11 override 和 final 不是属性?

我不知何故错过了C++11中引入的属性。现在我发现了,我想知道为什么override和final被添加为具有特殊含义的标识符,而不是作为标准属性。override的目的是产生编译时错误,这也是许多标准属性的目的。感觉好像它们符合这个概念,但我可能没有找到它的原因。 最佳答案 他们曾经是,在他们因评论而改变之前US44在C++11的FCD上:Evenifattributescontinuetobestandardizedovercontinuedobjectionsfrombothofthetwovendorswhoareciteda